package org.learn.java;

public class PrimeFactor {

	public static void main(String[] args) {

		int N = Integer.MAX_VALUE;
		for (int i = 0; i < 1000; i++) {

			usingSqrt(N - i);
			notUsingSqrt(N - i);
			System.out.println("-----------");
		}

	}

	private static void usingSqrt(int N) {
		double start = System.currentTimeMillis();
		for (int i = 2; i <= Math.sqrt(N); i++) {
			while (N % i == 0) {
				System.out.print(i + " ");
				N /= i;
			}
		}

		if (N > 1)
			System.out.print(N + " ");
		System.out.println(" total time: "
				+ ((double) System.currentTimeMillis() - start) / 1000.0);
	}

	private static void notUsingSqrt(int N) {
		double start = System.currentTimeMillis();
		for (int i = 2; i <= N / i; i++) {
			while (N % i == 0) {
				System.out.print(i + " ");
				N /= i;
			}
		}

		if (N > 1)
			System.out.print(N + " ");
		System.out.println(" total time: "
				+ ((double) System.currentTimeMillis() - start) / 1000.0);
	}
}
